﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="koik_dok_vastus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(KoikDokVastus))]
    public class KoikDokVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKoikDokVastus clazz;
        
        public KoikDokVastusSerializer(IKoikDokVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("dok");
            if (clazz.Dok!=null) {
                global::Xtee.Core.SerializationMetadata metaDok = this.GetMetaData(clazz.Dok);
                Writer.WriteTypeAttribute(metaDok.TypeQualifiedName.Namespace, metaDok.TypeQualifiedName.Name);
                metaDok.NewSerializer(clazz.Dok).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Dok");
            }
            Writer.WriteEndElement();
            if (clazz.Teade!=null) {
                Writer.WriteStartElement("teade");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Teade))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "dok")) {
                goto dok;
            }
            else {
                if ((Reader.LocalName == "teade")) {
                    goto teade;
                }
                else {
                    return;
                }
            }
        dok:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>koik_dok_vastus>dok");
            }
            global::Xtee.Core.SerializationMetadata metaDok = this.GetMetaData<KoikDokVastus.IDokType>(Reader, ">>koik_dok_vastus>dok", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
            clazz.Dok = metaDok.NewEntity<KoikDokVastus.IDokType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("dok");
                metaDok.NewSerializer(clazz.Dok).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        teade:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>koik_dok_vastus>teade");
            }
            clazz.Teade = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("teade")).Value;
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>koik_dok_vastus>dok", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(KoikDokVastus.DokType))]
        public class DokTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected KoikDokVastus.IDokType clazz;
            
            public DokTypeSerializer(KoikDokVastus.IDokType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Dok != null) 
                            && (x < clazz.Dok.Count)); x = (x + 1)) {
                    if (clazz.Dok[x]!=null) {
                        Writer.WriteStartElement("dok");
                        global::Xtee.Core.SerializationMetadata metaDok = this.GetMetaData(clazz.Dok[x]);
                        Writer.WriteTypeAttribute(metaDok.TypeQualifiedName.Namespace, metaDok.TypeQualifiedName.Name);
                        metaDok.NewSerializer(clazz.Dok[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="dok") {
                    clazz.Dok = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKoikDok>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "dok")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>koik_dok_vastus>dok>dok");
                        }
                        global::Xtee.Core.SerializationMetadata metaDok = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKoikDok>(Reader, "koik_dok", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKoikDok item = metaDok.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IKoikDok>();
                        clazz.Dok.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("dok");
                            metaDok.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
